import axios from 'axios'
import store from '@/store'
// import { Message } from 'element-ui'
// 创建了一个新的axios实例
const service = axios.create({
  baseURL: 'https://www.liulongbin.top:8888/api/private/v1', // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // 超时时间
})

// 请求拦截器
service.interceptors.request.use(
  config => {
    if (store.getters.token) {
      // 注入token
      config.headers['Authorization'] = `${store.getters.token}`
    }
    return config
  },
  err => {
    return Promise.reject(err)
  }
)

// 响应拦截器
service.interceptors.response.use()

export default service
